package com.gx.cn.hospitalmanage.HospitalManage;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import com.gx.cn.hospitalmanage.AActivity;
import com.gx.cn.hospitalmanage.R;
import com.gx.cn.hospitalmanage.tree.MyNodeBean;
import com.gx.cn.hospitalmanage.tree.Node;
import com.gx.cn.hospitalmanage.tree.TreeListViewAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by HCQ on 2018/1/8.
 */


public class PatientTransferZoneActivity extends AppCompatActivity {

    private ListView treeLv;
    private Button checkSwitchBtn;
    private MyTreeListViewAdapter<MyNodeBean> adapter;
    private List<MyNodeBean> mDatas = new ArrayList<MyNodeBean>();
    //标记是显示Checkbox还是隐藏
    private boolean isHide = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_patienttransferzone);

        initDatas();
        treeLv = (ListView) this.findViewById(R.id.tree_lv);


        try {
            adapter = new MyTreeListViewAdapter<MyNodeBean>(treeLv, this,
                    mDatas, 10, isHide);

            adapter.setOnTreeNodeClickListener(new TreeListViewAdapter.OnTreeNodeClickListener() {
                @Override
                public void onClick(Node node, int position) {
                    if (node.isLeaf()) {

                        Toast.makeText(getApplicationContext(), node.getName(),
                                Toast.LENGTH_SHORT).show();
                        Intent intent=new Intent();
                        intent.setClass(PatientTransferZoneActivity.this, AActivity.class);
                        startActivity(intent);
                    }
                }


                @Override
           public void onCheckChange(Node node, int position, List<Node> checkedNodes) {
                    // TODO Auto-generated method stub

                    StringBuffer sb = new StringBuffer();
                    for (Node n : checkedNodes) {
                        int pos = n.getId() - 1;
                        sb.append(mDatas.get(pos).getName()).append("---")
                                .append(pos + 1).append(";");
                    }

                    Toast.makeText(getApplicationContext(), sb.toString(),
                            Toast.LENGTH_SHORT).show();
                }

            });
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        treeLv.setAdapter(adapter);

    }

    private void initDatas() {

        mDatas.add(new MyNodeBean(1, 0, "住院病人一览表"));
        mDatas.add(new MyNodeBean(2, 1, "监护室"));
        mDatas.add(new MyNodeBean(3, 1, "一病区"));
        mDatas.add(new MyNodeBean(4, 1, "二病区"));
        mDatas.add(new MyNodeBean(5, 2, "李世民"));
        mDatas.add(new MyNodeBean(6, 2, "李白"));

        mDatas.add(new MyNodeBean(7, 3, "赵匡胤"));
        mDatas.add(new MyNodeBean(8, 3, "苏轼"));

        mDatas.add(new MyNodeBean(9, 4, "朱元璋"));
        mDatas.add(new MyNodeBean(10, 4, "唐伯虎"));
        mDatas.add(new MyNodeBean(11, 4, "文征明"));
        mDatas.add(new MyNodeBean(12, 7, "赵建立"));
        mDatas.add(new MyNodeBean(13, 8, "苏东东"));
        mDatas.add(new MyNodeBean(14, 10, "秋香"));

    }

}
